package com.dynastqin.controller;

import com.dynastqin.service.ServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeAction {
    private final static Logger log = LoggerFactory.getLogger(HomeAction.class);
    //尽管这里有静态变量，按道理在加载这个类时会初始化这个静态变量，但spring 容器初始化在类加载前面，故问题解决
    private static String project_name = ServiceUtils.PROJECT_NAME;

    //使用@ModelAttribute注解可以在返回视图的model中添加这些参数,参数类型必须是String,该注解的入参可以不存在、值为null
//    比如1、http://localhost:8088/home.do
//    2、http://localhost:8088/home.do?userName=
//    3、http://localhost:8088/home.do?userName=test
//    前1,2 获取的userName="";3获取userName="test"

    @RequestMapping("/home")
    public String home(@ModelAttribute("userName")String userName,
                       @ModelAttribute("isLogin")String isLogin,Model model) {
        model.addAttribute("msg", "hello,spring web world");
        System.out.println(userName);
        System.out.println(project_name);
        System.out.println(ServiceUtils.substract(1, 4));

        //log
        log.trace("======trace");
        log.debug("======debug");
        log.info("======info");
        log.warn("======warn");
        log.error("======error");
        return "home";
    }
}